<?php
function GetPromotionById($id,$type)
{
    global $dbsql,$language;
    $id         = intval($id);
    $sql_select = "select * from tblpromotions where iParentId=$id and cType='$type' and iStatus=1";
    return $dbsql->query_fetch($sql_select);
}

function ListTourPromotions()
{
    global $dbsql,$language;
    TImport('tour');
    
    $sql_select = "select tou.iId,tou.cUrlString,tou.cName,tou.cImage,tou.cDays,pro.cPrice,pro.dStartDate,pro.dEndDate
                     from tblpromotions as pro JOIN tblsettour as tou ON
                    pro.iParentId=tou.iId and pro.cType='tour' and tou.cLanguage='$language' and pro.iStatus=1
                    order by tou.iOrder  ";
    $rs         = $dbsql->query($sql_select);
    $rows       = $dbsql->num_rows($rs);
    if($rows==0)return;
    $return     = '<div id="List1" class="list">';
    $i          = 1;
    $isopendiv  = false;
    while($result   = $dbsql->fetch_array($rs))
    {
        $link    = GetLinkTourById($result['iId'],$result['cUrlString']); 
        
        if($i%5==1)
        {
            if($i>1)
            {
                $return.='</div>';
                $isopendiv=false;
            }
            $return .= '<div class="slide">';
            $isopendiv=true;
        }
        $i++;
        $return .= '<a class="listtour" href="'.$link.'" title="'.$result['cName'].'">';
        $return .= '<span class="img"><img src="'.GetIntroImg($result['cImage'],true).'" width="155" alt="'.$result['cName'].'" /></span>';
        $return .= '<span class="tt">'.$result['cName'];
        $return .= '<span class="d">'.$result['cDays'].'</span></span>';
        $return .= '<span class="w"><span class="red">'.getLang('Special Offer').": ".$result['cPrice'].'</span></span>';
        $return .= '<span class="l"></span>';
        $return .= '<span class="f">'.getLang('Find out more').'</span>';        
        $return .= '</a>';
    }
    if($isopendiv==true)
    {
        $return.='</div>';
    }
    if($rows==0)
    {
       // $return .= '<div class="notfound">'.getLang('Not found result!').'</div>';
    }
    $return     .= "<div class='clear'>&nbsp;</div></div>";
    if($rows>5)
    {
        $return     .= '<div class="ctr_pages">
                        <a href="#1" class="prevbut preva" onclick="anprot.goFrame(-1)">Previous</a>
                        <a href="#2" class="nextbut nexta" onclick="anprot.goFrame(1)">Next</a>
                    </div>  
                    <script type="text/javascript">
                        (anprot=new TrAnami).init({id:"List1",w:910,h:275,type:2,autotime:18000});
                    </script>';
    }
    return $return;
}

function ListHotelPromotions()
{
    global $dbsql,$language;
    TImport('hotel');
    
    $sql_select = "select tou.iParentId,tou.cUrlString,tou.cName,tou.cImage,pro.cPrice,pro.dStartDate,pro.dEndDate
                     from tblpromotions as pro JOIN tblhotel as tou ON
                    pro.iParentId=tou.iId and pro.cType='hotel' and tou.cLanguage='$language' and pro.iStatus=1
                    order by tou.iOrder  ";
    $rs         = $dbsql->query($sql_select);
    $rows       = $dbsql->num_rows($rs);
    if($rows==0)return;
    $return     = '<div id="List2" class="list">';
    $i          = 1;
    $isopendiv  = false;
    while($result   = $dbsql->fetch_array($rs))
    {
        $link    = getLinkHotel($result['iParentId'],$result['cUrlString']); 
        if($i%5==1)
        {
            if($i>1)
            {
                $return.='</div>';
                $isopendiv  = false;
            }
            $return .= '<div class="slide">';
            $isopendiv  = true;
        }
        $i++;
        $return .= '<a class="listtour" href="'.$link.'" title="'.$result['cName'].'">';
        $return .= '<span class="img"><img src="'.GetIntroImg($result['cImage'],true).'" width="155" alt="'.$result['cName'].'" /></span>';
        $return .= '<span class="tt">'.$result['cName'].'</span>';
        $return .= '<span class="w"><span class="red">'.getLang('Special Offer').": ".$result['cPrice'].'</span></span>';
        $return .= '<span class="l"></span>';
        $return .= '<span class="f">'.getLang('Find out more').'</span>';        
        $return .= '</a>';
    }
    
    if($isopendiv==true)
    {
        $return.='</div>';
    }
    
    if($rows==0)
    {
        //$return .= '<div class="notfound">'.getLang('Not found result!').'</div>';
    }
    $return     .= "<div class='clear'>&nbsp;</div></div>";
    if($rows>5)
    {
        $return     .= '<div class="ctr_pages">
                        <a href="#1" class="prevbut preva" onclick="anproh.goFrame(-1)">Previous</a>
                        <a href="#2" class="nextbut nexta" onclick="anproh.goFrame(1)">Next</a>
                    </div>  
                    <script type="text/javascript">
                        (anproh=new TrAnami).init({id:"List2",w:910,h:275,type:2,autotime:18000});
                    </script>';
    }
    return $return;
}